import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    // 使用懒加载技术 不用引入绝对路径
    path:'/login',
    name:'login',
    component:()=>import('@/views/login')
  },
  {
    path:'/',
    // 如果父路由默认有子路由 name可以省略
    // name:'layout',
    component:()=>import('@/views/layout'),
    children:[
      {
        // 当path为空时默认是有/符号 相当于是父路由的默认子路由 默认显示 home
        path:'',
        name:'home',
        component:()=>import('@/views/home')
      },
      {
        path: '/qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: '/video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: '/my',
        name: 'my',
        component: () => import('@/views/my')
      }
    ]
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  },
  {
    path: '/article/:articleId',
    name:'article',
    component: () => import('@/views/article'),
    props: true,//加上props让参数更好的提高利用
  },
  {
    path:'/user/profile',
    name:'user-profile',
    component: () => import('@/views/user-profile')
  }
]

const router = new VueRouter({
  routes
})

export default router
